public class Solution {
    public int singleNumber(int[] nums) {
        int ones = 0, twos = 0;
        for(int num : nums){
            ones = ones ^ num & ~twos;
            twos = twos ^ num & ~ones;
        }
        return ones;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,0,1,0,1,99};
        Solution solution = new Solution();
        System.out.println(solution.singleNumber(nums));
    }
}
